package com.maxmlr.music.system.controller;

import com.maxmlr.music.common.base.BaseController;
import com.maxmlr.music.common.bean.ResultBean;
import com.maxmlr.music.system.entity.Task;
import com.maxmlr.music.system.param.TaskParam;
import com.maxmlr.music.system.service.TaskService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * @author max
 * @version 1.0
 * @ClassName TaskController
 * @Description 控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-14
 */
@Slf4j
@RestController
@Api(value = "/system/task", tags = "Task 控制器")
@RequestMapping("/system/task")
public class TaskController extends BaseController<TaskService, Task> {

    @Autowired
    public TaskService service;

    /**
     * 保存
     *
     * @param param
     * @return ResultBean<Boolean>
     */
    @PostMapping
    @RequiresPermissions("system:task:add")
    public ResultBean<Boolean> save(TaskParam param) {
        return ResultBean.ok(service.saveParam(param));
    }

    /**
     * 修改
     *
     * @param param
     * @return ResultBean<Boolean>
     */
    @PutMapping
    @RequiresPermissions("system:task:edit")
    public ResultBean<Boolean> update(TaskParam param) {
        return ResultBean.ok(service.updateParam(param));
    }

    /**
     * 删除
     *
     * @param id
     * @return ResultBean<Boolean>
     */
    @DeleteMapping("/remove/{id}")
    @RequiresPermissions("system:task:remove")
    public ResultBean<Boolean> remove(@PathVariable("id") Serializable id) {
        return ResultBean.ok(service.removeById(id));
    }

    /**
     * 控制启停
     *
     * @param param
     * @return ResultBean<Boolean>
     */
    @PutMapping(value = "/change-status")
    public ResultBean<Boolean> changeJobStatus(TaskParam param) throws SchedulerException {
        return ResultBean.ok(service.changeStatus(param));
    }

}
